package com.ww.learn.funs

fun main() {
    val items = listOf(1, 2, 3, 4, 5)

    items.fold(0, { acc: Int, i: Int ->
        // 如果一个lambda表达式有参数，前面是参数，后跟->
        println("acc: $acc, i: $i")
        val result = acc + i
        println("result: $result")
        result
    })

    val joinedToString = items.fold("Elements:", { acc, i -> "$acc $i" })
    // 函数引用也可以用于高阶函数调用
    val product = items.fold(1, Int::times)

    println("joinedToString: $joinedToString")
    println("product: $product")
}